/***************************************************************************
*                                                                         *
*   This file is part of the Fotowall project,                            *
*       http://code.google.com/p/fotowall                                 *
*                                                                         *
*   Copyright (C) 2009 by Enrico Ros <enrico.ros@gmail.com>               *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
 * ----------------------------------------------------------------------- *
 *																		   *
 *	Modifications for FotoKinect, Spring 2011 by Gianna Badiali,		   *
 *                                                   Gabriel Fernandez,	   *
 *                                                   Kelsey Tripp, and     *
 *                                                   Sam Swarr             *
 *																		   *
 ***************************************************************************/

#include <QInputDialog>
#include "PictureConfig.h"
#include "PictureContent.h"
#include "GlowEffectDialog.h"
#include "ui_PictureConfig.h"
#include <QGraphicsSceneMouseEvent>
#include <QListWidgetItem>
#include <QSettings>

PictureConfig::PictureConfig(PictureContent * pictureContent, QGraphicsItem * parent)
	: AbstractConfig(pictureContent, parent)
	, m_pictureUi(new Ui::PictureConfig())
	, m_pictureContent(pictureContent)
{
	// WIDGET setup
	QWidget * pictureTab = new QWidget();
	m_pictureUi->setupUi(pictureTab);
	m_pictureUi->applyEffects->setEnabled(false);

	// add effects items to the listview
	QListWidgetItem *no_effect = new QListWidgetItem(QIcon(":/data/effects-icons/no-effect.png"), tr("No effects"), m_pictureUi->effectsList);
	no_effect->setData(Qt::UserRole, PictureEffect::ClearEffects);

	connect(m_pictureUi->invertButton, SIGNAL(clicked()), m_pictureContent, SIGNAL(flipVertically()));
	connect(m_pictureUi->flipButton, SIGNAL(clicked()), m_pictureContent, SIGNAL(flipHorizontally()));
	connect(m_pictureUi->cropButton, SIGNAL(clicked()), m_pictureContent, SIGNAL(crop()));
	// autoconnection doesn't work because we don't do ->setupUi(this), so here we connect manually
	connect(m_pictureUi->applyEffects, SIGNAL(clicked()), this, SLOT(on_applyEffects_clicked()));
	connect(m_pictureUi->effectsList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(on_effectsList_itemActivated(QListWidgetItem*)));
}

PictureConfig::~PictureConfig()
{
	delete m_pictureUi;
}

void PictureConfig::on_applyEffects_clicked()
{
	if (m_currentEffect.effect != PictureEffect::ClearEffects)
		emit applyEffect(m_currentEffect, true);
}

void PictureConfig::on_effectsList_itemActivated(QListWidgetItem * item)
{
	// get the effect class
	if (!item)
		return;

	m_pictureUi->applyEffects->setEnabled(false);
	int effect = item->data(Qt::UserRole).toUInt();
	qreal param = 0.0;

	// apply the effect
	m_currentEffect = PictureEffect((PictureEffect::Effect)effect, param);
	emit applyEffect(m_currentEffect, false);
	m_pictureUi->applyEffects->setEnabled(true);
}
